package demo1;

public class LeetCode35 {
    public int searchInsert(int[] nums, int target) {
        int left = 0, right = nums.length - 1;
        if (target <= nums[left]) return left;
        while (left < right) {
            int mid = left + (right - left + 1) / 2;
            if (nums[mid] > target) right = mid - 1;
            else if (nums[mid] < target) left = mid;
            else return mid;
        }
        return left + 1;
    }
}
